﻿#region Usings

using System.Data.Entity.ModelConfiguration;
using Rail.Net.Core.Model;

#endregion

namespace Rail.Net.Data.Configuration
{
    public class RuMap : EntityTypeConfiguration<Ru>
    {
        public RuMap()
        {
            ToTable("Rus");
            HasKey(ru => ru.Id);

            Property(ru => ru.Name).IsRequired().HasMaxLength(30);
            Property(ru => ru.Code).IsRequired().HasMaxLength(2);
            Property(ru => ru.CodeLong).IsRequired().HasMaxLength(6);
            
            HasMany(ru => ru.Stations).WithRequired(station => station.Ru);
            HasMany(ru => ru.RelationRus).WithRequired(relationRu => relationRu.Ru);
            HasMany(ru => ru.PriceSerials).WithRequired(priceSerial => priceSerial.Ru);
            HasMany(ru => ru.PriceDistances).WithRequired(priceDistance => priceDistance.Ru);

            HasMany(ru => ru.Tariffs).WithMany(tariff => tariff.Rus).Map(m =>
                                                                             {
                                                                                 m.ToTable("TariffRus");
                                                                                 m.MapLeftKey("Ru_Id");
                                                                                 m.MapRightKey("Tariff_Id");
                                                                             }
                );
        }
    }
}